package com.blb.thread;

import java.util.concurrent.atomic.AtomicInteger;

public class AtomicDemo {

    static AtomicInteger count = new AtomicInteger(0);

//    public static synchronized void add(){
//        count++;
//    }

    public static void main(String[] args) {
        for (int i = 0; i < 10000; i++) {
            new Thread(() -> {
                count.getAndIncrement(); // 1) 读取原始值 2) 计算原始值+1 3) 保存为新值
            }).start();
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("count=" + count);
    }
}
